<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<h:body>
	<ui:composition template="templatePrincipal.xhtml">

		<ui:define name="content">
			<h:form id="formCrud">

						<p:toolbar> 
						    <p:toolbarGroup align="right">
						        <p:commandButton value="Pesquisar" icon="ui-icon ui-icon-search"
						        	action="#{mbean.pesquisar}" update="@form" rendered="#{mbean.botaoPesquisar}"  onclick="dataTablePesquisa.getPaginator().setPage(0);"
						        		 oncomplete="limparPesquisa();"/>
				                <p:commandButton title="#{msg.acaoNovo}" value="#{msg.acaoNovo}" icon="ui-icon-circle-plus"
						        	action="#{mbean.novo}" update="@form" rendered="#{mbean.botaoNovo}"/>  
	    						<p:commandButton title="#{msg.acaoSalvar}" value="#{msg.acaoSalvar}"
							 		onclick="confirmacaoSalvar.show();" rendered="#{mbean.botaoSalvar}" icon="ui-icon-disk" type="button"/>
								<p:commandButton rendered="#{mbean.botaoExcluir}" title="#{msg.acaoExcluir}" value="#{msg.acaoExcluir}"
									onclick="confirmacaoExcluir.show();" type="button" icon="ui-icon-trash"/>
								<p:commandButton title="#{msg.acaoCancelar}" value="#{msg.acaoCancelar}"
									onclick="confirmacaoCancelar.show();" rendered="#{mbean.botaoCancelar}" icon="ui-icon-cancel" type="button"/>
						    </p:toolbarGroup>
    					</p:toolbar>
    					
    					<p:remoteCommand name="limparPesquisa" action="#{mbean.limparPesquisa}" update="panelPesquisa"/>
    					
						<p:confirmDialog message="Deseja excluir o registro?" header="Confirmação" severity="alert"
							widgetVar="confirmacaoExcluir" appendToBody="true" modal="true">
							<p:commandButton value="Sim" action="#{mbean.excluir}"
								immediate="true" update="@form" onclick="confirmacaoExcluir.hide();" />
							<p:commandButton value="Não" onclick="confirmacaoExcluir.hide(); " type="button"/> 	
						</p:confirmDialog>
						
						<p:confirmDialog message="Deseja salvar as alterações?" header="Confirmação" severity="alert"
							widgetVar="confirmacaoSalvar" appendToBody="true">
							<p:commandButton value="Sim" action="#{mbean.salvar}" update="@form" onclick="confirmacaoSalvar.hide();"/>
							<p:commandButton value="Não" onclick="confirmacaoSalvar.hide(); " type="button"/> 	
						</p:confirmDialog>
 						
						<p:confirmDialog message="Deseja cancelar as alterações?" header="Confirmação" severity="alert"
							widgetVar="confirmacaoCancelar" appendToBody="true">
							<p:commandButton value="Sim" action="#{mbean.pesquisar}" update="@form" onclick="confirmacaoCancelar.hide();" immediate="true"/>
							<p:commandButton value="Não" onclick="confirmacaoCancelar.hide(); " type="button"/> 	
						</p:confirmDialog>		
				
						<p:panel  header="#{tituloPesquisa}" rendered="#{mbean.botaoPesquisar}">
							<p:outputPanel layout="block" id="panelPesquisa">
								<ui:insert name="pesquisa"/>
							</p:outputPanel>
							
							<br />
							<p:outputPanel layout="block">
								<p:dataTable var="registro" value="#{mbean.lBean}" paginator="true" rows="8" widgetVar="dataTablePesquisa"
										emptyMessage="#{msg.msgGridVazia}" paginatorPosition="bottom">
									<f:facet name="header">
										<h:outputText value="#{tituloGrid}"/>
									</f:facet>
									<ui:insert name="gridPesquisa"/>
						          	<p:column style="width:32px">  
							             <p:commandLink action="#{mbean.editar(registro)}" update="@form" title="#{msg.acaoVisualizar}">
							             	<p:graphicImage value="#{resource['images/edit.png']}"/>
							             </p:commandLink>
									</p:column> 
								</p:dataTable>
							</p:outputPanel>
						</p:panel>
						
						<p:panel  header="#{tituloCadastro}" rendered="#{not mbean.botaoPesquisar}">
							<ui:insert name="cadastro"/>
						</p:panel>
						<p:growl showSummary="true" showDetail="true" globalOnly="true"/>			
					</h:form>
		</ui:define>
	</ui:composition>
</h:body>
</html>
